package com.CTAtracker.android.Adapters;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.CTAtracker.android.R;
import com.CTAtracker.android.Models.ColorStation;
import com.CTAtracker.android.Models.Line;

/**
 * This class is a adapter to the line
 */
public class LinesItemAdapter extends ArrayAdapter<Line>{	

	/**
	 * The layout to inflate
	 */
	private LayoutInflater _layoutInflater = null;
	/**
	 * The Id of the resource to inflate
	 */
	private int _resourceId = 0;
	/**
	 * The List of the Lines to adapt to the view
	 */
	private ArrayList<Line> _listLine;

	/**
	 * Constructor of the class. Instance the attribute and call the super method.
	 * @param context The context of the application
	 * @param resourceId The id of the resource to inflate 
	 * @param listStop the list of line to adapt to the view
	 */
	public LinesItemAdapter(Context context, int idResource, List<Line> objects) {
		super(context, idResource, 0, objects);

		_layoutInflater = LayoutInflater.from(context);
		_resourceId = idResource;
		_listLine = (ArrayList<Line>) objects; 
	}

	/**
	 * This method is called every time we want to display the view
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final Line line = _listLine.get(position);
		convertView = _layoutInflater.inflate(_resourceId, parent, false);
		String name = line.get_nameTrack(); 
		ColorStation colorStation = new ColorStation(line.get_color());

		TextView textView = (TextView) convertView.findViewById(R.id.textViewTrack);
		textView.setText(name);

		FrameLayout frameLayout = (FrameLayout) convertView.findViewById(R.id.frameColorTrack);
		frameLayout.setBackgroundColor(Color.parseColor(colorStation.toString()));

		return convertView;
	}
}
